﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

public class ExaminationMove:Examination
{
    public GameObject m_ExaminationPlace;
    public GameObject m_Destination;
    public GameObject m_ProtectedObject;

    public int m_CollisionCountMax = 3;

    public Text m_CollisionCountL;
    public int m_CollisionCountBigSucceedMax = 0;

    int m_CollisionCount = 0;
    protected override void Start()
    {
        base.Start();
        m_CollisionCountL.text = m_CollisionCount + "/" + m_CollisionCountMax;
    }

    protected override void Update()
    {
        base.Update();
    }

    protected override void CheckComplete()
    {
        base.CheckComplete();
        if (!m_Start)
            return;
        if (m_TimeCount > m_TimeMax ||
            m_ProtectedObject == null ||
            m_CollisionCount >= m_CollisionCountMax)
        {
            OnLose();
        }
    }

    protected override void OnLose()
    {
        m_CollisionCountL.color = new Vector4(1, 0, 0, 1);
        m_Start = false;
        base.OnLose();
    }
    public void OnCollision()
    {
        m_CollisionCount++;
        m_CollisionCountL.text = m_CollisionCount + "/" + m_CollisionCountMax;
        m_WarningSound.Stop();
        m_WarningSound.Play();
    }
    public override void OnSucceed()
    {
        base.OnSucceed();
        if (m_TimeCount < m_TimeBigSucceedMax &&
            m_CollisionCount <= m_CollisionCountBigSucceedMax)
        {
            m_BigSucceedSound.Play();
            Player.Instance.DriveLicenseState[(int)m_DriveLevel, 0] = (int)Driver.LicenseEvaluate.NIU_BI;
        }
        else 
        {
            m_SucceedSound.Play(); 
            if (Player.Instance.DriveLicenseState[(int)m_DriveLevel, 0] == (int)Driver.LicenseEvaluate.NOT_PASS)
                Player.Instance.DriveLicenseState[(int)m_DriveLevel, 0] = (int)Driver.LicenseEvaluate.PASS;
        }
        Player.Instance.save();
    }

}